<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f4f4f9;
        }
        .upload-container {
            text-align: center;
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        input[type="file"] {
            margin-bottom: 10px;
        }
        button {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        #status {
            margin-top: 20px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="upload-container">
        <h2>文件上传测试</h2>
        <form id="uploadForm" enctype="multipart/form-data">
            <input type="file" name="file" id="fileInput">
            <button type="button" onclick="uploadFile()">上传文件</button>
        </form>
        <div id="status"></div>
    </div>
    <script>
        function uploadFile() {
            const form = document.getElementById('uploadForm');
            const formData = new FormData(form);

            fetch('http://localhost:3000/upload', {
                method: 'POST',
                body: formData
            })
            .then(response => response.text())
            .then(data => {
                document.getElementById('status').innerText = data;
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('status').innerText = '上传失败: ' + error.message;
            });
        }
    </script>
</body>
</html>